package main

import "fmt"

func twoSum(nums []int, target int) []int {
	// key:val; value:index
	countMap := make(map[int]int, len(nums))
	arr := make([]int, 0)
	for i, v := range nums {
		needVal := target - v
		if j, ok := countMap[needVal]; ok {
			arr = append(arr, j)
			arr = append(arr, i)
			return arr
		}
		countMap[v] = i
	}
	return arr
}

func main() {
	res := twoSum([]int{1, 2, 3, 4}, 5)
	fmt.Println(res)
}
